package com.huluobo.a2110mvpimdemo.addFriend;

import com.huluobo.a2110mvpimdemo.IMApp;
import com.huluobo.a2110mvpimdemo.base.BasePresenter;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

/**
 * Created by LC on 2023/12/13.
 */
public class AddFriendPresenter extends BasePresenter<AddFriendContract.View> implements AddFriendContract.Presenter {
    @Override
    public void add(String username, String reason) {
        if (username.matches(IMApp.REGEX_USERNAME)) {
            EMClient.getInstance().contactManager().aysncAddContact(username, reason, new EMCallBack() {
                @Override
                public void onSuccess() {
                    if (isAttach()) {
                        getView().onAddSuccess();
                    }
                }

                @Override
                public void onError(int code, String error) {
                    if (isAttach()) {
                        getView().onAddFailed(error);
                    }
                }
            });
        } else {
            if (isAttach()) {
                getView().onAddFailed("用户名错误,首字符需要为英文,3-20位");
            }
        }
    }
}
